import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'

export function add(data) {
  data.password=encrypt(data.password)
  return request({
    url: 'admin/sysUser/add',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'admin/sysUser/'+ids,
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'admin/sysUser/edit',
    method: 'put',
    data
  })
}

export function editUser(obj) {
  return request({
    url: 'auth/auth/edit-user',
    method: 'post',
    data:obj
  })
}

export function updatePass(obj) {
  const data = {
    oldPass: encrypt(obj.oldPass),
    newPass: encrypt(obj.newPass)
  }
  return request({
    url: 'auth/auth/edit-user-password',
    method: 'post',
    data:data
  })
}

export function updateEmail(form) {
  const data = {
    password: encrypt(form.password),
    email: form.email,
    code:form.code
  }
  return request({
    url: 'auth/auth/edit-user-email',
    method: 'post',
    data:data
  })
}

export function frozenUser(obj) {
  return request({
    url: 'admin/sysUser/frozen-user',
    method: 'post',
    data:obj
  })
}

/**
 * 获取用户年级，班级
 * @param obj
 * @returns {*}
 */
export function getBranchLists(obj) {
  return request({
    url: 'admin/sysUser/get-grade-classes',
    method: 'post',
    data:obj
  })
}

/**
 * 学生绑定班级
 * @param obj
 * @returns {*}
 */
export function bindData(obj) {
  return request({
    url: 'admin/sysUser/bind-class',
    method: 'post',
    data:obj
  })
}

/**
 * 获取角色用户
 * @param roleId
 * @returns {*}
 */
export function getStudents(roleId) {
  return request({
    url: 'admin/sysUser/list/by-role/'+roleId,
    method: 'get',
    data:roleId
  })
}


/**
 * 系统用户分页数据
 * @param roleId
 * @returns {*}
 */
export function sysUserPages(query) {
  return request({
    url: 'admin/sysUser/page',
    method: 'get',
    params: query
  })
}


/**
 * 导出用户列表
 * @param obj
 * @returns {*}
 */
export function exportUserLists(obj) {
  return request({
    url: 'admin/sysUser/export-user-list',
    method: 'post',
    data: obj
  })
}


/**
 * 根据id 获取信息
 * @param obj
 * @returns {AxiosPromise}
 */
export function getUserInfoById(userId) {
  return request({
    url: 'admin/sysUser/get-by-id/'+userId,
    method: 'post',
  })
}






export default { add, edit, del ,frozenUser,getBranchLists,bindData}

